//
//  ViewController.swift
//  5.1.Adding Gravity to Your UI Components
//
//  Created by joker on 15/7/30.
//  Copyright (c) 2015年 joker. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var squareView: UIView?
    var animator: UIDynamicAnimator?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(animated: Bool) {
        squareView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
        
        if let theSquareView = squareView {
            theSquareView.backgroundColor = UIColor.greenColor()
            theSquareView.center = view.center
            view.addSubview(theSquareView)
            animator = UIDynamicAnimator(referenceView: view)
            if let theAnimator = animator {
                let gravity = UIGravityBehavior(items: [theSquareView])
                theAnimator.addBehavior(gravity)
            }
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

